SaveAsDOCX(ICollection<String>,String,Boolean) Method
Saves the provided collection of OCR results, identifiable by their unique IDs, to a docx file.
public function SaveAsDOCX(
: ICollection;
: String;
: Boolean
): GdPictureStatus;
public function SaveAsDOCX(
: ICollection,
: String,
: boolean
) : GdPictureStatus;
public: GdPictureStatus SaveAsDOCX(
ICollection<string*>* ,
string* ,
bool
)
public:
GdPictureStatus SaveAsDOCX(
ICollection<String^>^ ,
String^ ,
bool
)
'Declaration
Public Overloads Function SaveAsDOCX( _
ByVal As ICollection(Of String), _
ByVal As String, _
ByVal As Boolean _
) As GdPictureStatus
Parameters
- OCRResultIDs
- A collection of the unique OCR result identifiers. It specifies the OCR results you want to save.
- FilePath
- The path to the file where the results will be saved. If the specified file already exists, it will be overwritten.
- KeepLineBreaks
- The flag indicating whether to keep line breaks or not when saving the results.
Return Value
A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.
We strongly recommend always checking this status first.
How to save a collection of the OCR results to a docx file.
Dim caption As String = "Example: SaveAsDOCX"
Using gdpictureOCR As GdPictureOCR = New GdPictureOCR
'Set up your prefered parameters for OCR.
gdpictureOCR.ResourcesFolder = "\\GdPicture.Net 14\\redist\\OCR"
If gdpictureOCR.AddLanguage(OCRLanguage.English) = GdPictureStatus.OK Then
'Set up the image you want to process.
Dim gdpictureImaging As GdPictureImaging = New GdPictureImaging
'The standard open file dialog displays to allow you to select the file.
Dim image As Integer = gdpictureImaging.CreateGdPictureImageFromFile("")
If (gdpictureImaging.GetStat = GdPictureStatus.OK) AndAlso
(gdpictureOCR.SetImage(image) = GdPictureStatus.OK) Then
Dim results As List(Of String) = New List(Of String)()
'Run the first OCR process.
'Note that gdpictureOCR.OCRMode = OCRMode.FavorSpeed by default.
Dim resID1 As String = gdpictureOCR.RunOCR
If gdpictureOCR.GetStat = GdPictureStatus.OK Then
results.Add(resID1)
Else
MessageBox.Show("The first OCR process has failed with the status: " + gdpictureOCR.GetStat.ToString, caption)
End If
'Change OCR settings.
gdpictureOCR.OCRMode = OCRMode.FavorAccuracy
'Run the second OCR process.
Dim resID2 As String = gdpictureOCR.RunOCR
If gdpictureOCR.GetStat = GdPictureStatus.OK Then
results.Add(resID2)
Else
MessageBox.Show("The second OCR process has failed with the status: " + gdpictureOCR.GetStat.ToString, caption)
End If
If results.Count > 0 Then
'Save the results.
If gdpictureOCR.SaveAsDOCX(results, "OCR_results.docx", True) = GdPictureStatus.OK Then
MessageBox.Show("The OCR results has been successfully saved.", caption)
Else
MessageBox.Show("The SaveAsDOCX() method has failed with the status: " + gdpictureOCR.GetStat.ToString, caption)
End If
End If
'Release the used image.
gdpictureImaging.ReleaseGdPictureImage(image)
Else
MessageBox.Show("The error occurred when setting up the image: " + gdpictureImaging.GetStat.ToString + " or " + gdpictureOCR.GetStat.ToString, caption)
End If
gdpictureImaging.Dispose()
Else
MessageBox.Show("The AddLanguage() method has failed with the status: " + gdpictureOCR.GetStat.ToString, caption)
End If
gdpictureOCR.ReleaseOCRResults()
End Using
string caption = "Example: SaveAsDOCX";
using (GdPictureOCR gdpictureOCR = new GdPictureOCR())
{
//Set up your prefered parameters for OCR.
gdpictureOCR.ResourcesFolder = "\\GdPicture.Net 14\\redist\\OCR";
if (gdpictureOCR.AddLanguage(OCRLanguage.English) == GdPictureStatus.OK)
{
//Set up the image you want to process.
GdPictureImaging gdpictureImaging = new GdPictureImaging();
//The standard open file dialog displays to allow you to select the file.
int image = gdpictureImaging.CreateGdPictureImageFromFile("");
if ((gdpictureImaging.GetStat() == GdPictureStatus.OK) &&
(gdpictureOCR.SetImage(image) == GdPictureStatus.OK))
{
List<string> results = new List<string>();
//Run the first OCR process.
//Note that gdpictureOCR.OCRMode = OCRMode.FavorSpeed by default.
string resID1 = gdpictureOCR.RunOCR();
if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
results.Add(resID1);
else
MessageBox.Show("The first OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
//Change OCR settings.
gdpictureOCR.OCRMode = OCRMode.FavorAccuracy;
//Run the second OCR process.
string resID2 = gdpictureOCR.RunOCR();
if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
results.Add(resID2);
else
MessageBox.Show("The second OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
if (results.Count > 0)
{
//Save the results.
if (gdpictureOCR.SaveAsDOCX(results, "OCR_results.docx", true) == GdPictureStatus.OK)
MessageBox.Show("The OCR results has been successfully saved.", caption);
else
MessageBox.Show("The SaveAsDOCX() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
}
//Release the used image.
gdpictureImaging.ReleaseGdPictureImage(image);
}
else
MessageBox.Show("The error occurred when setting up the image: " + gdpictureImaging.GetStat().ToString() + " or " + gdpictureOCR.GetStat().ToString(), caption);
gdpictureImaging.Dispose();
}
else
MessageBox.Show("The AddLanguage() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
gdpictureOCR.ReleaseOCRResults();
}